var gulp = require("gulp"),
browserSync = require("browser-sync").create(),
reload = function(){
    browserSync.reload();
},
sass = require("gulp-sass"),
autoprefixer = require("gulp-autoprefixer");





var src = {
	src:'src/',
	scss:'src/scss/**/*scss',
	html:'src/**/*.html',
	js:'src/js/**/*.js'
}

gulp.task('server',function(){
	browserSync.init({
		server:{
			baseDir:src.src,
			index:'syz-cjss-.html'
		},
		open:'external',
		prot:8080
	});
	gulp.watch(src.js).on('change',function(){
		reload()
	});
	gulp.watch(src.html).on('change',function(){
		reload()
	});
	gulp.watch(src.scss).on('change',function(){
		reload();
		gulp.src(src.scss)
		.pipe(sass({outputStyle:'expanded'}).on('error',sass.logError))
		.pipe(autoprefixer('>5%'))
		.pipe(gulp.dest('src/css'))
		
	})
	
})
gulp.task('sass',function(){
	reload();
	gulp.src(src.scss)
	.pipe(sass({outputStyle:'expanded'}).on('error',sass.logError))
	.pipe(autoprefixer('>5%'))
	.pipe(gulp.dest('src/css'))
})


gulp.task('default',['server','sass'],function(){
	console.log("任务已执行，在8080端口！");
})
